#include <iostream>

template<typename T>
void Swap(T& a,T& b)
{
    T temp = a;
    a = b;
    b = temp;
}


//只对动态数组起作用
template<typename T> 
void Sort(T *a,int len)
{
    for(int i = 0; i < len - 1; i++)
    {
        for(int j = 0; j < len - i - 1; j++)
        {
            if(a[j] > a[j+1])
                Swap<T>(a[j],a[j+1]);
        }
    }
}

template<typename T>
void PrintArray(T *a,int len)
{
    for(int i = 0; i < len; i++)
    {
        std::cout<<a[i]<<" ";
    }
    std::cout<<std::endl;
}

class Student
{
public:
    Student(int id,const std::string& name):id(id),name(name){}
    bool operator>(const Student& s)
    {
        return this->id > s.id;
    }
    friend std::ostream& operator<<(std::ostream& os,const Student& s);
private:
    int id;
    std::string name;
};

std::ostream& operator<<(std::ostream& os,const Student& s)
{
    std::cout<<s.id<<" "<<s.name;
    return os;
}

int main()
{
    Student a[3] = {{3,"zhangsan"},{1,"lisi"},{2,"wangwu"}};
    //模板的显式调用
    Sort<Student>(a,3);
    PrintArray<Student>(a,3);
    return 0;
}